// pages/myBankCard/myBankCardAdd.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seleted: "",
    name:"",
    bankNane:"",
    bankNo:"",
    bankNoTo:"",
    Iphone:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navT: app.globalData.navTop,
      navLH: app.globalData.navLineHeight,
      navH: app.globalData.navHeight,
      modelmes: app.globalData.modelmes
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      token: wx.getStorageSync("token")
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //是否选中
  checkedTap: function () {
    var checked = this.data.checked;
    this.setData({
      "checked": !checked
    })
  },
  //提交
  save: function (e) {
    var userid = wx.getStorageSync("userId");
    var that = this;
    console.info(that.data.name);
    if(that.data.name == "") {
      wx.showToast({
        title: '姓名不能为空！',
        icon: "none"
      })
      return false
    }
    if (that.data.Iphone == "") {
      wx.showToast({
        title: '手机号不能为空！',
        icon: "none"
      })
      return false
    }
    if (that.data.bankNo == "") {
      wx.showToast({
        title: '地址不能为空！',
        duration: 2000,
        icon: 'none'
      });
      return false;
    }
    wx.request({
      url: app.globalData.url + 'userUpgrade',
      data: {
        userId: wx.getStorageSync("userId"),
        userLevel: 3,
        hisId: 0,
        realname: that.data.name,
        telephone: that.data.Iphone,
        address: that.data.bankNo,
        remark: that.data.remark,
      },
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var resultData = res.data;
        var hisId = resultData.hisId;
        if (res.data.result != 1 && res.data.result != 9) {
          wx.showToast({
            title: "数据异常，请稍后重试",
            icon: 'none'
          })
          return;
        } else {
          setTimeout(function () { // 做了个延时重试一次，作为保底。
            wx.showToast({
              title: res.data.errmsg,
              icon: "none",
              duration: 2000,      //停留时间
            })
          }, 500)
          wx.navigateBack({
            detail:3
          })
        }

      }
    })
    
  },
  name: function (e) {
    this.setData({
      name: e.detail.value,
    })
  },
  bankNane: function (e) {
    this.setData({
      bankNane: e.detail.value,
    })
  },
  bankNo: function (e) {
    this.setData({
      bankNo: e.detail.value,
    })
  },
  remark: function (e) {
    this.setData({
      remark: e.detail.value,
    })
  },
  Iphone: function (e) {
    this.setData({
      Iphone: e.detail.value,
    })
  },
  agreement:function(){
    wx.navigateTo({
      url: '/pages/webView/webView?url=' + app.globalData.url + 'getWebPage&webId=userServiceProtocol'
      //url: '/pages/webView/webView?url=http://47.104.96.96/yixuanqi/getWebPage'
    })
  },
  navBack: function () {
    wx.navigateBack({

    })
  }
})